package com.lxw.oa.util;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import com.google.gson.Gson;

public class ChartsUtil {
	
	/**
	 * 获取图表默认颜色
	 * @param index
	 * @return
	 */
	public static String getColor(int index) {
		
		String color = "";
		String colorStr = "#00C0EF,#FCCE10,#DA70D6,#32CD32,#FF8C69,#B5C334,#8B4513,#FF00FF,#00008B,"
				+ "#A020F0,#9ACD32,#919191,#2B821D,#8B0A50,#FE8463,#9BCA63,#FAD860,#F3A43B,#60C0DD,"
				+ "#D7504B,#C6E579,#F4E001,#F0805A,#26C0C0,#FF7F50,#6495ED,"
				+ "#FF69B4,#BA55D3,#CD5C5C,#FFA500,#40E0D0,#1E90FF,#FF6347,#7B68EE,#00FA9A,#FFD700,"
				+ "#6B8E23,#FF00FF,#3CB371,#B8860B,#30E0E0 "
				+"#00C0EF,#FCCE10,#DA70D6,#32CD32,#FF8C69,#B5C334,#8B4513,#FF00FF,#00008B,"
				+ "#A020F0,#9ACD32,#919191,#2B821D,#8B0A50,#FE8463,#9BCA63,#FAD860,#F3A43B,#60C0DD,"
				+ "#D7504B,#C6E579,#F4E001,#F0805A,#26C0C0,#FF7F50,#6495ED,"
				+ "#FF69B4,#BA55D3,#CD5C5C,#FFA500,#40E0D0,#1E90FF,#FF6347,#7B68EE,#00FA9A,#FFD700,"
				+ "#6B8E23,#FF00FF,#3CB371,#B8860B,#30E0E0 ";
		String[] arr = colorStr.split(",");
		if(index > arr.length) {
			index = arr.length-1;
		}
		for(int i=0; i<arr.length; i++) {
			color = arr[index];
		}
		
		return color;
	}
	
	/**
	 * 获取单列表最大值
	 * @param list
	 * @return
	 */
	public static String getMaxValList(List list) {
		return Collections.max(list).toString();
	}
	
	/**
	 * 获取组合列表最大值
	 * @param list
	 * @return
	 */
	public static String getMaxValList2(List list) {
		List max_list = new ArrayList();
		List<Integer> inner_list2 = new ArrayList<Integer>();
		if(list != null && list.size() > 0) {
			List inner_list = null;
			for(int i=0,j=list.size(); i<j; i++) {
				inner_list = (List) list.get(i);
				for (int k = 0; k < inner_list.size(); k++) {
					inner_list2.add(Integer.valueOf(inner_list.get(k).toString()));
				}
				max_list.add(Collections.max(inner_list2));
			}
		}
		return getMaxValList(max_list);
	}
	
	/**
	 * 获取一维柱状图Option
	 * @param func_name
	 * @param is_title
	 * @param is_legend
	 * @param is_toolbox
	 * @param tList
	 * @param xList
	 * @param yList
	 * @return
	 */
	public static String getBarOption(String func_name, int is_title, int is_legend, int is_toolbox, int is_xychg, int is_stack, 
			String x_name, String y_name, List<Object> tList, List<Object> xList, 
			List<Object> yList, List<Object> cList, List<Object> wList) {
		
		StringBuffer optSB = new StringBuffer();
		optSB.append("{");
		
		if(!StringUtil.isEmpty(func_name) && is_title == 1) {
			optSB.append("title : { text:'"+ func_name +"' },");
		}
		if(!StringUtil.isEmpty(cList)) {
			optSB.append("color : [");
			for(int i=0,j=cList.size(); i<j; i++) {
				String c = String.valueOf(cList.get(i));
				if(StringUtil.isEmpty(c) || "null".equals(c)) {
					c = getColor(i);
				}
				optSB.append("'"+ c +"',");
			}
			optSB.deleteCharAt(optSB.lastIndexOf(","));
			optSB.append("],");
		}
		optSB.append("tooltip : { trigger:'axis', axisPointer : { type : 'shadow' } },");
		if(!StringUtil.isEmpty(tList) && is_legend == 1) {
			optSB.append("legend : {");
			optSB.append("data:[");
			for(int i=0,j=tList.size(); i<j; i++) {
				String t = String.valueOf(tList.get(i));
				if(t == null || "null".equals(t)) { t = ""; }
				optSB.append("'"+ t +"',");
			}
			optSB.deleteCharAt(optSB.lastIndexOf(","));
			optSB.append("]");
			optSB.append("},");
		}
		optSB.append("toolbox : { ");
		if(is_toolbox == 1) {
			optSB.append("  show : true,");
		} else {
			optSB.append("  show : false,");
		}
		optSB.append("  feature : { mark : {show: true},dataView : {show: true, readOnly: false}, ");
		optSB.append("    magicType : {show: true, type: ['line', 'bar']}, restore : {show: true}, saveAsImage : {show: true}}");
		optSB.append("},");
		optSB.append("calculable : true,");
		
		if(is_xychg == 1) {
			optSB.append("yAxis : [{");
		} else {
			optSB.append("xAxis : [{");
		}
		if(!StringUtil.isEmpty(x_name)) {
			optSB.append("name : '"+ x_name +"',");
		}
		optSB.append("type : 'category',");
		if(!StringUtil.isEmpty(xList)) {
			optSB.append("data : [");
			int x_len = 0;
			List<Object> _xl = (List<Object>) xList.get(0);
			for(int i=0,j=xList.size(); i<j; i++) {
				x_len = _xl.size();
				for(int m=0,n=_xl.size(); m<n; m++) {
					optSB.append("'"+ String.valueOf(_xl.get(m)) +"',");
				}
			}
			if (_xl.size()!=0) {
				optSB.deleteCharAt(optSB.lastIndexOf(","));
			}
			optSB.append("]");
			if(x_len >= 6) {
				optSB.append(",axisLabel:{ interval:0,rotate:30 }");
			}
		} else {
			optSB.append("data : []");
		}
		optSB.append("}],");
		
		if(is_xychg == 1) {
			optSB.append("xAxis : [{ ");
		} else {
			optSB.append("yAxis : [{ ");
		}
		if(!StringUtil.isEmpty(y_name)) {
			optSB.append("name : '"+ y_name +"',");
		}
		optSB.append("type : 'value'");
		optSB.append("}],");
		
		optSB.append("series : [");
		if(!StringUtil.isEmpty(yList)) {
			for(int i=0,j=yList.size(); i<j; i++) {
				List<Object> _yl = (List) yList.get(i);
				String _t = "";
				String _w = "";
				if(!StringUtil.isEmpty(tList)) { _t = String.valueOf(tList.get(i)); }
				if(!StringUtil.isEmpty(wList)) { _w = String.valueOf(wList.get(i)); }
				if(_t == null || "null".equals(_t)) { _t = ""; }
				optSB.append("{");
				optSB.append("name : '"+ _t +"',");
				optSB.append("type :'bar',");
				if(is_stack == 1) {
					optSB.append("stack :'"+ x_name +"',");
				}
				if(!StringUtil.isEmpty(_w)) {
					optSB.append("barWidth : "+ _w +",");
				}
				optSB.append("data : [");
				for(int m=0,n=_yl.size(); m<n; m++) {
					optSB.append(String.valueOf(_yl.get(m))+",");
				}
				if (_yl.size()!=0) {
					optSB.deleteCharAt(optSB.lastIndexOf(","));
				}
				optSB.append("],");
//				optSB.append("markPoint : { data : [{type : 'max', name: '最大值'}, {type : 'min', name: '最小值'}] },");
//				optSB.append("markLine : { data : [{type : 'average', name: '平均值'}] }");
				optSB.append("label:{normal:{show:true,position:'top'}}");
				optSB.append("},");
			}
			optSB.deleteCharAt(optSB.lastIndexOf(","));
		}
		optSB.append("]");
		optSB.append("}");
		
		Gson gson= new Gson();
		String json = gson.toJson(optSB.toString());
		
		return json;
	}
	
	/**
	 * 获取一维饼图Option
	 * @param func_name
	 * @param is_title
	 * @param is_legend
	 * @param is_toolbox
	 * @param x_name
	 * @param y_name
	 * @param tList
	 * @param xList
	 * @param yList
	 * @return
	 */
	public static String getPieOption(String func_name, int is_title, int is_legend, int is_toolbox, int is_torus, 
			String x_name, String y_name, List<Object> tList, 
			List<Object> xList, List<Object> yList, List<Object> cList) {
		
		StringBuffer optSB = new StringBuffer();
		optSB.append("{");
		
		if(!StringUtil.isEmpty(func_name) && is_title == 1) {
			optSB.append("title : { text:'"+ func_name +"', x:'left' },");
		}
		if(!StringUtil.isEmpty(yList)) {
			optSB.append("color : [");
			for(int i=0,j=yList.size(); i<j; i++) {
				List _yl = (List) yList.get(i);
				for(int m=0,n=_yl.size(); m<n; m++) {
					String c = getColor(m);
					optSB.append("'"+ c +"',");
				}
			}
			List<Object> list0 = (List<Object>) yList.get(0);
			if (list0.size()!=0) {
				optSB.deleteCharAt(optSB.lastIndexOf(","));
			}
			optSB.append("],");
		}
		optSB.append("tooltip : { trigger:'item',formatter: \"{a} <br/>{b} : {c} ({d}%)\" },");
		if(!StringUtil.isEmpty(tList) && is_legend == 1) {
			optSB.append("legend : { orient : 'vertical', x : 'left',");
			optSB.append("data:[");
			for(int i=0,j=tList.size(); i<j; i++) {
				String t = String.valueOf(tList.get(i));
				if(t == null || "null".equals(t)) { t = ""; }
				optSB.append("'"+ t +"',");
			}
			optSB.deleteCharAt(optSB.lastIndexOf(","));
			optSB.append("]");
			optSB.append("},");
		}
		optSB.append("toolbox : { ");
		if(is_toolbox == 1) {
			optSB.append("  show : true,");
		} else {
			optSB.append("  show : false,");
		}
		optSB.append("  feature : { mark : {show: true},dataView : {show: true, readOnly: false}, ");
		optSB.append("    magicType : {show: true, type: ['pie', 'funnel'], ");
		optSB.append("     option: { funnel: { x: '25%', width: '50%', funnelAlign: 'center', max: 1548 } }}, ");
		optSB.append("    restore : {show: true}, saveAsImage : {show: true}}");
		optSB.append("},");
		optSB.append("calculable : true,");
		
		optSB.append("series : [");
		if(!StringUtil.isEmpty(yList)) {
			int len = yList.size();
			if(len <= 1) {
				List<Object> _yl = (List<Object>) yList.get(0);
				List<Object> _xl = (List<Object>) xList.get(0);
				String _t = "";
				if(!StringUtil.isEmpty(tList)) { _t = String.valueOf(tList.get(0)); }
				if(_t == null || "null".equals(_t)) { _t = ""; }
				optSB.append("{");
				optSB.append("name : '"+ _t +"',");
				if(is_torus == 1) {
					optSB.append("type :'pie', radius : [ '50%', '70%' ], avoidLabelOverlap : false,");
					optSB.append("label : {");
					optSB.append("normal : {show : false,position : 'center'},");
					optSB.append("emphasis : {show : true,textStyle : {fontSize : '30',fontWeight : 'bold'}}");
					optSB.append("},");
					optSB.append("labelLine : {normal : {show : false}},");
				} else {
//					optSB.append("type :'pie', radius : '55%', center: ['50%', '50%'],label: {normal: {show: true,formatter: '{b}: {c}({d}%)'}},");
					optSB.append("type :'pie', radius : '55%', center: ['50%', '50%'],");
				}
				optSB.append("data : [");
				for(int m=0,n=_yl.size(); m<n; m++) {
					optSB.append("{ value : "+String.valueOf(_yl.get(m))+", name : '"+ String.valueOf(_xl.get(m)) +"' },");
				}
				if (_yl.size()!=0) {
					optSB.deleteCharAt(optSB.lastIndexOf(","));
				}
				optSB.append("]");
				optSB.append("}");
				
			} else {
				for(int i=0; i<len; i++) {
					List _yl = (List) yList.get(i);
					List _xl = (List) xList.get(i);
					String _t = "";
					if(!StringUtil.isEmpty(tList)) { _t = String.valueOf(tList.get(i)); }
					if(_t == null || "null".equals(_t)) { _t = ""; }
					optSB.append("{");
					optSB.append("name : '"+ _t +"',");
					optSB.append("type :'pie', ");
					if(i ==0) {
						optSB.append("selectedMode: 'single',radius: [0, '30%'],");
						optSB.append("label: { normal: { position: 'inner' } },");
						optSB.append("labelLine: { normal: { show: false } },");
						
					} else {
						optSB.append("radius: ['40%', '55%'],");
						
					}
					optSB.append("data : [");
					for(int m=0,n=_yl.size(); m<n; m++) {
						optSB.append("{ value : "+String.valueOf(_yl.get(m))+", name : '"+ String.valueOf(_xl.get(m)) +"' },");
					}
					optSB.deleteCharAt(optSB.lastIndexOf(","));
					optSB.append("]");
					optSB.append("},");
				}
				optSB.deleteCharAt(optSB.lastIndexOf(","));
			}
		}
		optSB.append("]");
		optSB.append("}");
		
		Gson gson= new Gson();
		String json = gson.toJson(optSB.toString());
		
		return json;
	}
	
	/**
	 * 获取折线图Option
	 * @param func_name
	 * @param is_title
	 * @param is_legend
	 * @param is_toolbox
	 * @param x_name
	 * @param y_name
	 * @param tList
	 * @param xList
	 * @param yList
	 * @return
	 */
	public static String getLineOption(String func_name, int is_title, int is_legend, int is_toolbox, 
			String x_name, String y_name, List<Object> tList, 
			List<Object> xList, List<Object> yList, List<Object> cList) {
		
		StringBuffer optSB = new StringBuffer();
		optSB.append("{");
		
		if(!StringUtil.isEmpty(func_name) && is_title == 1) {
			optSB.append("title : { text:'"+ func_name +"' },");
		}
		if(!StringUtil.isEmpty(cList)) {
			optSB.append("color : [");
			for(int i=0,j=cList.size(); i<j; i++) {
				String c = String.valueOf(cList.get(i));
				if(StringUtil.isEmpty(c) || "null".equals(c)) {
					c = getColor(i);
				}
				optSB.append("'"+ c +"',");
			}
			optSB.deleteCharAt(optSB.lastIndexOf(","));
			optSB.append("],");
		}
		optSB.append("tooltip : { trigger:'axis' },");
		if(!StringUtil.isEmpty(tList) && is_legend == 1) {
			optSB.append("legend : {");
			optSB.append("data:[");
			for(int i=0,j=tList.size(); i<j; i++) {
				String t = String.valueOf(tList.get(i));
				if(t == null || "null".equals(t)) { t = ""; }
				optSB.append("'"+ t +"',");
			}
			optSB.deleteCharAt(optSB.lastIndexOf(","));
			optSB.append("]");
			optSB.append("},");
		}
		optSB.append("toolbox : { ");
		if(is_toolbox == 1) {
			optSB.append("  show : true,");
		} else {
			optSB.append("  show : false,");
		}
		optSB.append("  feature : { mark : {show: true},dataView : {show: true, readOnly: false}, ");
		optSB.append("    magicType : {show: true, type: ['line', 'bar']}, ");
		optSB.append("    restore : {show: true}, saveAsImage : {show: true}}");
		optSB.append("},");
		optSB.append("calculable : true,");
		
		optSB.append("xAxis : [{");
		if(!StringUtil.isEmpty(x_name)) {
			optSB.append("name : '"+ x_name +"',");
		}
		optSB.append("type : 'category',boundaryGap : false,");
		if(!StringUtil.isEmpty(xList)) {
			optSB.append("data : [");
			int x_len = 0;
			List<Object> _xl = (List<Object>) xList.get(0);
			for(int i=0,j=xList.size(); i<j; i++) {
				x_len = _xl.size();
				for(int m=0,n=_xl.size(); m<n; m++) {
					optSB.append("'"+ String.valueOf(_xl.get(m)) +"',");
				}
			}
			if (_xl.size()!=0) {
				optSB.deleteCharAt(optSB.lastIndexOf(","));
			}
			optSB.append("]");
			if(x_len >= 6) {
				optSB.append(",axisLabel:{ interval:0,rotate:30 }");
			}
		} else {
			optSB.append("data : []");
		}
		optSB.append("}],");
		optSB.append("yAxis : [{ ");
		if(!StringUtil.isEmpty(y_name)) {
			optSB.append("name : '"+ y_name +"',");
		}
		optSB.append("type : 'value'");
		optSB.append("}],");
		optSB.append("series : [");
		if(!StringUtil.isEmpty(yList)) {
			for(int i=0,j=yList.size(); i<j; i++) {
				List<Object> _yl = (List) yList.get(i);
				String _t = "";
				if(!StringUtil.isEmpty(tList)) { _t = String.valueOf(tList.get(i)); }
				if(_t == null || "null".equals(_t)) { _t = ""; }
				optSB.append("{");
				optSB.append("name : '"+ _t +"',");
				optSB.append("type :'line',");
				optSB.append("data : [");
				for(int m=0,n=_yl.size(); m<n; m++) {
					optSB.append(String.valueOf(_yl.get(m))+",");
				}
				if (_yl.size()!=0) {
					optSB.deleteCharAt(optSB.lastIndexOf(","));
				}
				optSB.append("],");
				optSB.append("markPoint : { data : [{type : 'max', name: '最大值'}, {type : 'min', name: '最小值'}] },");
				optSB.append("markLine : { data : [{type : 'average', name: '平均值'}] }");
				optSB.append("},");
			}
			optSB.deleteCharAt(optSB.lastIndexOf(","));
		}
		optSB.append("]");
		optSB.append("}");
		
		Gson gson= new Gson();
		String json = gson.toJson(optSB.toString());
		
		return json;
	}
	
	/**
	 * 获取仪表盘Option
	 * @param func_name
	 * @param is_title
	 * @param is_legend
	 * @param is_toolbox
	 * @param x_name
	 * @param y_name
	 * @param tList
	 * @param xList
	 * @param yList
	 * @return
	 */
	public static String getGaugeOption(String func_name, int is_title, int is_legend, int is_toolbox, 
			String x_name, String y_name, List<Object> tList, 
			List<Object> xList, List<Object> yList, List<Object> cList) {
		return null;
	}
	
	/**
	 * 获取雷达图Option
	 * @param func_name
	 * @param is_title
	 * @param is_legend
	 * @param is_toolbox
	 * @param x_name
	 * @param y_name
	 * @param tList
	 * @param xList
	 * @param yList
	 * @return
	 */
	public static String getRadarOption(String func_name, int is_title, int is_legend, int is_toolbox, 
			String x_name, String y_name, List<Object> tList, 
			List<Object> xList, List<Object> yList, List<Object> cList) {
		
		StringBuffer optSB = new StringBuffer();
		optSB.append("{");
		
		if(!StringUtil.isEmpty(func_name) && is_title == 1) {
			optSB.append("title : { text:'"+ func_name +"' },");
		}
		if(!StringUtil.isEmpty(cList)) {
			optSB.append("color : [");
			for(int i=0,j=cList.size(); i<j; i++) {
				String c = String.valueOf(cList.get(i));
				if(StringUtil.isEmpty(c) || "null".equals(c)) {
					c = getColor(i);
				}
				optSB.append("'"+ c +"',");
			}
			optSB.deleteCharAt(optSB.lastIndexOf(","));
			optSB.append("],");
		}
		optSB.append("tooltip : {},");
		if(!StringUtil.isEmpty(tList) && is_legend == 1) {
			optSB.append("legend : {");
			optSB.append("data:[");
			for(int i=0,j=tList.size(); i<j; i++) {
				String t = String.valueOf(tList.get(i));
				if(t == null || "null".equals(t)) { t = ""; }
				optSB.append("'"+ t +"',");
			}
			optSB.deleteCharAt(optSB.lastIndexOf(","));
			optSB.append("]");
			optSB.append("},");
		}
		optSB.append("toolbox : { ");
		if(is_toolbox == 1) {
			optSB.append("  show : true,");
		} else {
			optSB.append("  show : false,");
		}
		optSB.append("  feature : { mark : {show: true},dataView : {show: true, readOnly: false}, ");
		optSB.append("    restore : {show: true}, saveAsImage : {show: true}}");
		optSB.append("},");
		
		String max = getMaxValList2(yList);
		String max2 = String.valueOf(Integer.parseInt(max)*1);
		optSB.append("polar : [{");
		optSB.append(" indicator : [");
		if(!StringUtil.isEmpty(xList)) {
			List<Object> _xl = (List<Object>) xList.get(0);
			for(int i=0,j=_xl.size(); i<j; i++) {
				optSB.append("{ text: '"+ String.valueOf(_xl.get(i)) +"', max: "+ max2 +"},");
			}
			if(_xl.size()!=0) {
				optSB.deleteCharAt(optSB.lastIndexOf(","));
			}
		}
		optSB.append(" ]");
		optSB.append("}],");
		optSB.append("calculable : true,");
		
		optSB.append("series : [{");
		if(!StringUtil.isEmpty(func_name) && is_title == 1) {
			optSB.append("name : '"+ func_name +"' ,");
		}
		optSB.append("type :'radar',");
		optSB.append("data : [");
		if(!StringUtil.isEmpty(yList)) {
			for(int i=0,j=yList.size(); i<j; i++) {
				List<Object> _yl = (List) yList.get(i);
				String _t = "";
				if(!StringUtil.isEmpty(tList)) { _t = String.valueOf(tList.get(i)); }
				if(_t == null || "null".equals(_t)) { _t = ""; }
				optSB.append("{");
				optSB.append("value : [");
				for(int m=0,n=_yl.size(); m<n; m++) {
					optSB.append(String.valueOf(_yl.get(m))+",");
				}
				if (_yl.size()!=0) {
					optSB.deleteCharAt(optSB.lastIndexOf(","));
				}
				optSB.append("],");
				optSB.append("name : '"+ _t +"'");
				optSB.append(",label: {normal:{show: true,formatter:function(params) {return params.value;}}}},");
			}
			optSB.deleteCharAt(optSB.lastIndexOf(","));
		}
		optSB.append("]");
		optSB.append("}]");
		optSB.append("}");
		
		Gson gson= new Gson();
		String json = gson.toJson(optSB.toString());
		
		return json;
	}
	
	/**
	 * 获取散点图Option
	 * @param func_name
	 * @param is_title
	 * @param is_legend
	 * @param is_toolbox
	 * @param x_name
	 * @param y_name
	 * @param tList
	 * @param xList
	 * @param yList
	 * @return
	 */
	public static String getScatterOption(String func_name, int is_title, int is_legend, int is_toolbox, 
			String x_name, String y_name, String x_field, String y_field, String x_measure, String y_measure, 
			List<Object> tList, List<Object> xList, List<Object> yList, List<Object> xyList, List<Object> cList) {
		
		StringBuffer optSB = new StringBuffer();
		optSB.append("{");
		
		if(!StringUtil.isEmpty(func_name) && is_title == 1) {
			optSB.append("title : { text:'"+ func_name +"' },");
		}
		if(!StringUtil.isEmpty(cList)) {
			optSB.append("color : [");
			for(int i=0,j=cList.size(); i<j; i++) {
				String c = String.valueOf(cList.get(i));
				if(StringUtil.isEmpty(c) || "null".equals(c)) {
					c = getColor(i);
				}
				optSB.append("'"+ c +"',");
			}
			optSB.deleteCharAt(optSB.lastIndexOf(","));
			optSB.append("],");
		}
		optSB.append("tooltip : { trigger:'axis',showDelay: 0,");
		optSB.append(" formatter : function (params) {");
		optSB.append(" if (params.value.length > 1) {");
		optSB.append("     return params.seriesName + ' :<br/>' + params.value[0] + '"+ x_measure +" ' + params.value[1] + '"+ y_measure +" ';");
		optSB.append(" } else {");
		optSB.append("    return params.seriesName + ' :<br/>' + params.name + ' : ' + params.value + '"+ y_measure +" ';");
		optSB.append(" }");
		optSB.append(" }, ");
		optSB.append(" axisPointer:{ show: true,type : 'cross',lineStyle: { type : 'dashed',width : 1 } }");
		optSB.append("},");
		
		if(!StringUtil.isEmpty(tList) && is_legend == 1) {
			optSB.append("legend : {");
			optSB.append("data:[");
			for(int i=0,j=tList.size(); i<j; i++) {
				String t = String.valueOf(tList.get(i));
				if(t == null || "null".equals(t)) { t = ""; }
				optSB.append("'"+ t +"',");
			}
			optSB.deleteCharAt(optSB.lastIndexOf(","));
			optSB.append("]");
			optSB.append("},");
		}
		optSB.append("toolbox : { ");
		if(is_toolbox == 1) {
			optSB.append("  show : true,");
		} else {
			optSB.append("  show : false,");
		}
		optSB.append("  feature : { mark : {show: true},dataZoom : {show: true},dataView : {show: true, readOnly: false}, ");
		optSB.append("    restore : {show: true}, saveAsImage : {show: true}}");
		optSB.append("},");
		
		optSB.append("xAxis : [{");
		if(!StringUtil.isEmpty(x_name)) {
			optSB.append("name : '"+ x_name +"',");
		}
		optSB.append("type : 'value',scale:true,axisLabel : { formatter: '{value} "+x_measure+"' }");
		optSB.append("}],");
		optSB.append("yAxis : [{ ");
		if(!StringUtil.isEmpty(y_name)) {
			optSB.append("name : '"+ y_name +"',");
		}
		optSB.append("type : 'value',scale:true,axisLabel : { formatter: '{value} "+y_measure+"' }");
		optSB.append("}],");
		optSB.append("series : [");
		if(!StringUtil.isEmpty(xyList)) {//x,y轴数据
			for(int i=0,j=xyList.size(); i<j; i++) {
				List<Object> _xyl = (List<Object>) xyList.get(i);
				String _t = "";
				if(!StringUtil.isEmpty(tList)) { _t = String.valueOf(tList.get(i)); }
				if(_t == null || "null".equals(_t)) { _t = ""; }
				optSB.append("{");
				optSB.append("name : '"+ _t +"',");
				optSB.append("type :'scatter',");
				optSB.append("data : [");
				for(int m=0,n=_xyl.size(); m<n; m++) {
					Map _map = (Map) _xyl.get(m);
					String _x = String.valueOf(_map.get(x_field.toUpperCase()));
					String _y = String.valueOf(_map.get(y_field.toUpperCase()));
					String _d = "["+ _x +","+ _y +"]";
					optSB.append(_d+",");
				}
				optSB.deleteCharAt(optSB.lastIndexOf(","));
				optSB.append("],");
				optSB.append("markPoint : { data : [{type : 'max', name: '最大值'}, {type : 'min', name: '最小值'}] },");
				optSB.append("markLine : { data : [{type : 'average', name: '平均值'}] }");
				optSB.append("},");
			}
			optSB.deleteCharAt(optSB.lastIndexOf(","));
		}
		optSB.append("]");
		optSB.append("}");
		
		Gson gson= new Gson();
		String json = gson.toJson(optSB.toString());
		
		return json;
	}
	
	/**
	 * 获取关系图Option
	 * @param func_name
	 * @param is_title
	 * @param is_legend
	 * @param is_toolbox
	 * @param x_name
	 * @param y_name
	 * @param tList
	 * @param xList
	 * @param yList
	 * @return
	 */
	public static String getRelationOption(String func_name, int is_title, int is_legend, int is_toolbox, 
			String x_name, String y_name, List<Object> tList, 
			List<Object> xList, List<Object> yList, List<Object> cList) {
		return null;
	}
	
	/**
	 * 获取字符云Option
	 * @param func_name
	 * @param is_title
	 * @param is_legend
	 * @param is_toolbox
	 * @param x_name
	 * @param y_name
	 * @param tList
	 * @param xList
	 * @param yList
	 * @return
	 */
	public static String getWordcloudOption(String func_name, int is_title, int is_legend, int is_toolbox, 
			String x_name, String y_name, List<Object> tList, 
			List<Object> xList, List<Object> yList, List<Object> cList) {
		
		StringBuffer optSB = new StringBuffer();
		optSB.append("{");
		
		if(!StringUtil.isEmpty(func_name) && is_title == 1) {
			optSB.append("title : { text:'"+ func_name +"', x:'left' },");
		}
		optSB.append("tooltip : { show: true },");
		optSB.append("series : [{");
		if(!StringUtil.isEmpty(yList)) {
			for(int i=0,j=yList.size(); i<j; i++) {
				List<Object> _xl = (List) xList.get(i);
				List<Object> _yl = (List) yList.get(i);
				String _t = "";
				if(!StringUtil.isEmpty(tList)) { _t = String.valueOf(tList.get(i)); }
				if(_t == null || "null".equals(_t)) { _t = ""; }
				optSB.append("");
				optSB.append("name : '"+ _t +"',");
				optSB.append("type : 'wordCloud',");
				optSB.append("size : ['80%', '80%'],");
				optSB.append("textRotation : [0, 45, 90, -45],");
				optSB.append("textPadding : 0,");
				optSB.append("autoSize : { enable: true,minSize: 14 },");
				optSB.append("data : [");
				for(int m=0,n=_yl.size(); m<n; m++) {
					optSB.append("{");
					optSB.append(" name: '"+ String.valueOf(_xl.get(m)) +"',");
					optSB.append(" value: "+ String.valueOf(_yl.get(m)) +",");
					if(m == 0) {
						optSB.append(" textStyle: { normal: { color: 'black' } } ");
					} else {
						optSB.append(" textStyle: createRandomItemStyle() ");
					}
					optSB.append("},");
				}
				if (_yl.size()!=0) {
					optSB.deleteCharAt(optSB.lastIndexOf(","));
				}
				optSB.append("],");
			}
			optSB.deleteCharAt(optSB.lastIndexOf(","));
		}
		optSB.append("}]");
		optSB.append("}");
		
		Gson gson= new Gson();
		String json = gson.toJson(optSB.toString());
		
		return json;
	}
	
	/**
	 * 获取地图Option
	 * @param func_name
	 * @param is_title
	 * @param is_legend
	 * @param is_toolbox
	 * @param x_name
	 * @param y_name
	 * @param tList
	 * @param xList
	 * @param yList
	 * @return
	 */
	public static String getMapOption(String func_name, int is_title, int is_legend, int is_toolbox, 
			String x_name, String y_name, List<Object> tList, 
			List<Object> xList, List<Object> yList, List<Object> cList) {
		return null;
	}

}
